package com.letv.whatslive.model.convert;

import com.letv.whatslive.model.CP;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import org.apache.commons.lang3.StringUtils;

//2015.11.4

/**
 * Created by shenyue on 2015/11/4.
 */
public class CPConvert {
    public static DBObject castCPToDBObject(CP cp){
        DBObject dbo = new BasicDBObject();
        if(cp.getId()!=null){
            dbo.put("_id",cp.getId());
        }

        if(StringUtils.isNotBlank(cp.getPcode())){
            dbo.put("pcode",cp.getPcode());
        }else{
            dbo.put("pcode","");
        }

        if(StringUtils.isNotBlank(cp.getCpDescribe())){
            dbo.put("cpDescribe",cp.getCpDescribe());
        }else{
            dbo.put("cpDescribe","");
        }

        return dbo;


//        DBObject dbo = new BasicDBObject();
//        if (device.getId() != null) {
//            dbo.put("_id", device.getId());
//        }
//        dbo.put("platformId",device.getPlatformId());
//        dbo.put("sysVer", device.getSysVer());
//        dbo.put("model", device.getModel());
//        dbo.put("appVer", device.getAppVer());
//        dbo.put("corporationId", device.getCorporationId());
//        dbo.put("channelId", device.getChannelId());
//        return dbo;
    }

    public static CP castDBObjectToCP(DBObject dbObject){
        CP cp = new CP();
        if(dbObject != null) {
            cp.setId(ObjUtils.toLong(dbObject.get("_id")));
            cp.setCpDescribe(ObjUtils.toString(dbObject.get("cpDescribe")));
            cp.setPcode(ObjUtils.toString(dbObject.get("pcode")));
        }

        return cp;
    }
}
